package com.leyou.auth.web;

import com.leyou.auth.dto.UserDetail;
import com.leyou.auth.service.UserAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/user")
public class UserAuthController {

    @Autowired
    private UserAuthService userAuthService;

    /**
     * 用户授权
     * @param username
     * @param password
     * @return
     */
    @RequestMapping("login")
    public ResponseEntity<Void> userAuth(
            HttpServletResponse response,
            @RequestParam("username")String username,
            @RequestParam("password")String password) {

        this.userAuthService.userAuth(response,username,password);
        return ResponseEntity.ok().build();
    }


    /**
     * 用户退出登录
     * @param request
     * @param response
     * @return
     */
    @PostMapping("/logout")
    public ResponseEntity<Void> userLogout(HttpServletRequest request, HttpServletResponse response) {

        this.userAuthService.userLogout(request,response);
        return ResponseEntity.ok().build();

    }

}
